$(document).ready(function() {
    $(".hover-div").hover(function() {
        var offset = $(this).offset();
        var width = $(this).outerWidth();
        var height = $(this).outerHeight();
        var infoWidth = $(".info-div").outerWidth();
        var scrollTop = $(window).scrollTop();

        var grjj = $(this).attr("grjj");
        if(grjj=="undefined"||grjj==""||grjj==null){
            grjj = "此人很懒,还没有填写个人简介。";
        }
        $(".yhjj").text("个人简介:"+grjj);
        $(".username").text($(this).attr("username"));
        $(".info_img").attr("src",$(this).attr("userimg"))
        var h = $(".info-div").outerHeight();
        var top = offset.top - h - scrollTop ;
        var left = offset.left + width / 2 - infoWidth / 2 ;
        if(top<0){
            top = top + h + height ;
        }
        if(left<0){
            left = 0 ;
        }
        var listbg = ['https://gd-hbimg.huaban.com/be81e835fd0020c99b6e61a2052ebaa51694484146f3f-qGP4E3_fw658webp','https://gd-hbimg.huaban.com/0b02bae7cf147b9d3102570c6d6dc25fc2fdf8e049fde-Yl5zkm_fw240webp','https://gd-hbimg.huaban.com/4e6db62af227cc5c885f2a57e7ef977afee2130817e58a-OmILyz_fw240webp','https://gd-hbimg.huaban.com/e1d10699bad88724e1ffd660928e3188a564ffe59e3f-8uyDg3_fw240webp','https://gd-hbimg.huaban.com/632c7d0c373c42924c43fa9ceda58a67e95f3d691ae02-qkz5WM_fw240webp','https://gd-hbimg.huaban.com/a3855ff3c41fbd8f9a7711d75b7fecf1cc17be131e9a6-HKBBwL_fw240webp'];
        var randomNumber = Math.floor(Math.random() * 6);
        var bgimg = listbg[randomNumber];
        $(".info-div").css({
            "top": top + "px", // 70 是提示框的高度
            "left": left + "px",
            "background-image": "url("+bgimg+")"
        }).show();
    }, function() {
        $(".info-div").hide();
    });
    $(".info-div").hover(function() {
        $(".info-div").show();
    }, function() {
        $(".info-div").hide();
    });
});

window.addEventListener('scroll', () => {
    // 计算需要更新的top值
    $('.info-div').hide();
});